#!/usr/bin/env ruby

require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require 'haml'
require 'sass'

log = '/tmp/log.txt'
out = '/tmp/out.txt'

get '/' do
	haml :index
end

post '/command' do
	cmd = params[:command]
	if cmd =~ /commands|execute|submit/ 
		cmd += " do |m| File.open('#{out}','w') { |f| f.puts m } end"
	end
	File.open(log,'a') {|f| f.puts cmd }
	haml :submit
end

get '/result' do
	haml :result
end

get '/log' do
	content_type 'text/plain'
	`cat #{log}`
end

get '/out' do
	content_type 'text/plain'
	`cat #{out}`
end


get '/stylesheets/style.css' do
	content_type 'text/css', :charset => 'utf-8'
	sass :style
end

